home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / sys / amiga / programmer / 4354 < prev    next >
Encoding:
Internet Message Format  |  1996-08-05  |  1.5 KB

  1. Path: walt.tsc.com!not-for-mail
  2. From: billr@elmer.tsc.com (Bill Roberts)
  3. Newsgroups: comp.sys.amiga.programmer
  4. Subject: Re: x ^= y ^= x ^= y;
  5. Date: 27 Feb 1996 19:21:09 -0500
  6. Organization: Technology Service Corporation
  7. Sender: Bill Roberts
  8. Message-ID: <4h075l$2go@elmer.tsc.com>
  9. References: <1286.6624T1439T237@cs.ruu.nl> <4gij61$81i@news.ox.ac.uk> <3131C523.1ECC@sapiens.com>
  10. NNTP-Posting-Host: elmer.tsc.com
  11.  
  12. In article <3131C523.1ECC@sapiens.com>, Avi Lev  <avil@sapiens.com> wrote:
  13. >Benjamin Hutchings wrote:
  14. >> 
  15. >
  16. >it'll damn right WILL work because this is proper C syntax and 
  17. >therefore must work, if it doesn't then your compiler had better 
  18. >be replaced for a real C compiler cuz it obviously isn't one.
  19. What expression result will be in x at the end of the expression?  The
  20. first one or the second one?  The compiler may choose either.  The c
  21. standard specifically says that the results of this statement are
  22. undefined.  Consider the following: 
  23.    x = 1;
  24.    y = 2;
  25.    x = y += x += y;
  26. Will x contain 3 or 5.  It depends on what order the compiler stores
  27. the results of the expressions in the statement.  This is the same
  28. problem you will have with
  29.    i = 1;
  30.    x[ i++ ] = y[ i++ ];
  31. What will be the value of i at the end?  And which value will be used
  32. for which array?  It is up to the compiler, and specifically declared
  33. to be undefined in the c standard.  
  34.  
  35. General rule, never assign two values to the same variable in an
  36. expression.  
  37.  
  38. This same topic was the topic of a discussion for several weeks over
  39. on the comp.lang.c group several weeks ago.
  40.  
  41.  
  42.  
  43.